//
//  CenterTwoCell.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/9/28.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "CenterTwoCell.h"

@implementation CenterTwoCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}


-(void)createSubViews{
    self.scrollDataArray = @[@"张默默参加了比赛",@"李大默参加了比赛",@"王小默参加了比赛",@"刘默默参加了比赛"];
    _index = 0;
    UIImageView *iconImageView = [[UIImageView alloc] init];
    iconImageView.image = [UIImage imageNamed:@"热点推送"];
    [self.contentView addSubview:iconImageView];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(scaleLeftAndRight(13));
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(33), scaleTopAndBottom(35)));
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    UIView *shuxianView = [[UIView alloc] init];
    shuxianView.backgroundColor = COLOR_HEX(0xE1E1E1);
    [self.contentView addSubview:shuxianView];
    [shuxianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.mas_equalTo(0.5);
        make.height.mas_equalTo(26);
        make.left.equalTo(iconImageView.mas_right).offset(11.5);
    }];
    UIImageView *iconView = [[UIImageView alloc] init];
    iconView.image = [UIImage imageNamed:@"centerpagelaba"];
    [self.contentView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(12), scaleTopAndBottom(10)));
        make.top.equalTo(self.contentView.mas_top).offset(17);
        make.left.equalTo(iconImageView.mas_right).offset(23);
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = COLOR_HEX(0x121212);
    titleLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:titleLabel];
    titleLabel.text = @"元旦招募!募集狗年生肖";
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_right).offset(scaleLeftAndRight(5));
        make.height.mas_equalTo(15);
        make.centerY.equalTo(iconView.mas_centerY);
        make.width.mas_equalTo(scaleLeftAndRight(140));
    }];
    UILabel *saishiLabel = [[UILabel alloc] init];
    saishiLabel.text = @"赛事";
    saishiLabel.font = [UIFont systemFontOfSize:10];
    saishiLabel.textColor = COLOR_HEX(0xffc91f);
    saishiLabel.layer.borderColor = COLOR_HEX(0xffc91f).CGColor;
    saishiLabel.layer.borderWidth = 0.5f;
    saishiLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:saishiLabel];
    [saishiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(iconView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(27, 15));
        make.left.equalTo(titleLabel.mas_right).offset(1);
    }];
   _detailLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_detailLabel];
    _detailLabel.text = self.scrollDataArray[0];
    _detailLabel.textColor = COLOR_HEX(0x999999);
    _detailLabel.font = [UIFont systemFontOfSize:12];
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_right).offset(scaleLeftAndRight(5));
        make.top.equalTo(titleLabel.mas_bottom).offset(8);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-15);
    }];
    UIImageView *rightImageView = [[UIImageView alloc] init];
    rightImageView.image = [UIImage imageNamed:@"形状2"];
    [self.contentView addSubview:rightImageView];
    [rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-27));
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(62), scaleTopAndBottom(42)));
    }];
    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(scroll) userInfo:nil repeats:YES];
}
-(void)scroll{
    _index += 1;
    if (_index == self.scrollDataArray.count) {
        _index = 0;
    }
    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromTop;
    [self.detailLabel.layer addAnimation:transition forKey:@"trans"];
    NSInteger idx = _index;
    self.detailLabel.text = self.scrollDataArray[idx];
}
@end
